package cn.ym.mall.dao.impl;

import cn.ym.mall.dao.ProvinceDao;
import cn.ym.mall.entity.City;
import cn.ym.mall.entity.Province;
import cn.ym.mall.utils.DruidUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author 漆家乐
 * 省实现类
 */
public class ProvinceDaoImpl implements ProvinceDao {
    QueryRunner queryRunner = new QueryRunner();
    /**
     * 查询所有省份
     *
     * @return
     * @throws SQLException
     */
    @Override
    public List<Province> getProvince() throws SQLException {
        List<Province> provinceList = new ArrayList<Province>();
        try{
            String sql = "select * from province;";
            provinceList = queryRunner.query(DruidUtils.getConnection(),sql,new BeanListHandler<Province>(Province.class));
        }catch (Exception e){
            e.printStackTrace();
        }
        return provinceList;
    }
}
